




/*
'===============================================================================
'  HNG.Portal.BL.TblDownloadManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblDownloadManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_LangId="LangId";
				
				public const String Field_TieuDe="TieuDe";
				
				public const String Field_Link="Link";
				
				public const String Field_TrangThai="TrangThai";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblDownloadManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_LangId,typeof(int));
			
						
			
			dt.Columns.Add(Field_TieuDe,typeof(string));
			
						
			
			dt.Columns.Add(Field_Link,typeof(string));
			
						
			
			dt.Columns.Add(Field_TrangThai,typeof(bool));
			
			            
            return dt;			
		}
			
		public TblDownloadEntity Convert_Entity(TblDownloadEntity _TblDownloadEntity,TblDownloadEntity _TblDownloadEntity_XML)
		{	
			
				
			_TblDownloadEntity.Id= _TblDownloadEntity_XML.Id;
				
			_TblDownloadEntity.LangId= _TblDownloadEntity_XML.LangId;
				
			_TblDownloadEntity.TieuDe= _TblDownloadEntity_XML.TieuDe;
				
			_TblDownloadEntity.Link= _TblDownloadEntity_XML.Link;
				
			_TblDownloadEntity.TrangThai= _TblDownloadEntity_XML.TrangThai;
				
			
			return _TblDownloadEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblDownloadEntity Insert(TblDownloadEntity TblDownloadEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblDownloadEntity, true);
			}
			return TblDownloadEntity;
		}

		
		public TblDownloadEntity Insert(int Id, int LangId, string TieuDe, string Link, bool TrangThai)
		{
			TblDownloadEntity _TblDownloadEntity = new TblDownloadEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblDownloadEntity.Id = Id;
				_TblDownloadEntity.LangId = LangId;
				_TblDownloadEntity.TieuDe = TieuDe;
				_TblDownloadEntity.Link = Link;
				_TblDownloadEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblDownloadEntity, true);
			}
			return _TblDownloadEntity;
		}

		public TblDownloadEntity Insert(int LangId, string TieuDe, string Link, bool TrangThai)
		{
			TblDownloadEntity _TblDownloadEntity = new TblDownloadEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblDownloadEntity.LangId = LangId;
				_TblDownloadEntity.TieuDe = TieuDe;
				_TblDownloadEntity.Link = Link;
				_TblDownloadEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblDownloadEntity, true);
			}
			return _TblDownloadEntity;
		}

		public bool Update(TblDownloadEntity _TblDownloadEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblDownloadFields.Id == _TblDownloadEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblDownloadEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblDownloadEntity _TblDownloadEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblDownloadEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, int LangId, string TieuDe, string Link, bool TrangThai)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblDownloadEntity _TblDownloadEntity = new TblDownloadEntity(Id);
				if (adapter.FetchEntity(_TblDownloadEntity))
				{
				
					_TblDownloadEntity.LangId = LangId;
					_TblDownloadEntity.TieuDe = TieuDe;
					_TblDownloadEntity.Link = Link;
					_TblDownloadEntity.TrangThai = TrangThai;
					adapter.SaveEntity(_TblDownloadEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblDownloadEntity _TblDownloadEntity = new TblDownloadEntity(Id);
				if (adapter.FetchEntity(_TblDownloadEntity))
				{
					adapter.DeleteEntity(_TblDownloadEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblDownloadEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDownloadEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByLangId(int LangId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDownloadEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTieuDe(string TieuDe)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.TieuDe == TieuDe);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDownloadEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByLink(string Link)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.Link == Link);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDownloadEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTrangThai(bool TrangThai)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDownloadEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblDownloadEntity SelectOne(int Id)
		{
			TblDownloadEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblDownloadEntity _TblDownloadEntity = new TblDownloadEntity(Id);
				if (adapter.FetchEntity(_TblDownloadEntity))
				{
					toReturn = _TblDownloadEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblDownloadCollection = new EntityCollection( new TblDownloadEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDownloadCollection, null, 0, null);
			}
			return _TblDownloadCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDownloadCollection = new EntityCollection(new TblDownloadEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDownloadCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblDownloadCollection = new EntityCollection(new TblDownloadEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDownloadCollection, filter, 0, null);
			}
			return _TblDownloadCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDownloadCollection = new EntityCollection(new TblDownloadEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDownloadCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByLangId(int LangId)
		{
			EntityCollection _TblDownloadCollection = new EntityCollection(new TblDownloadEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDownloadCollection, filter, 0, null);
			}
			return _TblDownloadCollection;
		}
		
		// Return DataTable
		public DataTable SelectByLangIdRDT(int LangId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDownloadCollection = new EntityCollection(new TblDownloadEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDownloadCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTieuDe(string TieuDe)
		{
			EntityCollection _TblDownloadCollection = new EntityCollection(new TblDownloadEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.TieuDe == TieuDe);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDownloadCollection, filter, 0, null);
			}
			return _TblDownloadCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTieuDeRDT(string TieuDe)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDownloadCollection = new EntityCollection(new TblDownloadEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.TieuDe == TieuDe);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDownloadCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByLink(string Link)
		{
			EntityCollection _TblDownloadCollection = new EntityCollection(new TblDownloadEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.Link == Link);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDownloadCollection, filter, 0, null);
			}
			return _TblDownloadCollection;
		}
		
		// Return DataTable
		public DataTable SelectByLinkRDT(string Link)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDownloadCollection = new EntityCollection(new TblDownloadEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.Link == Link);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDownloadCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTrangThai(bool TrangThai)
		{
			EntityCollection _TblDownloadCollection = new EntityCollection(new TblDownloadEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDownloadCollection, filter, 0, null);
			}
			return _TblDownloadCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTrangThaiRDT(bool TrangThai)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDownloadCollection = new EntityCollection(new TblDownloadEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDownloadFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDownloadCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
